package com.itheima;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectinosDemo {
    public static void main(String[] args) {
        test1();
        test2();
    }

    private static void test2() {
        List<Integer> list=new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5);
        //正序
        Collections.sort(list);
        list.forEach(System.out::println);
//        Collections.sort(list,new Comparator<Integer>() {
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                return o2-o1;
//            }
//        });
        Collections.sort(list, (o1, o2) -> o2-o1);

        System.out.println("-------3--------");
        list.forEach(System.out::println);

        System.out.println("-------4--------");
        List<Student> list1=new ArrayList<>();
        list1.add(new Student("Tom",20));
        list1.add(new Student("Jerry",25));
        list1.add(new Student("Mike",18));
        Collections.sort(list1);
        list1.forEach(System.out::println);
    }

    private static void test1() {
        //ArrayList<String> list = new ArrayList<>();
        List<String> list = new ArrayList<>();//多态
        Collections.addAll(list,"A","B","C","D");
        System.out.println("-------1--------");
        list.forEach(System.out::println);

        //随机排序
        System.out.println("-------2--------");
        Collections.shuffle(list);
        list.forEach(System.out::println);


    }


}
